package com.fanfanwang.ffw.app.net;
/*package com.fanfanw.fanfwmessenger.net;

import java.util.ArrayList;

import com.fanfanw.fanfwmessenger.net.HttpRequest.HttpRequestException;
import com.fanfanw.fanfwmessenger.net.ParamsList.FileParameter;
import com.fanfanw.fanfwmessenger.net.ParamsList.HeaderParameter;
import com.fanfanw.fanfwmessenger.net.ParamsList.InputStreamParameter;
import com.fanfanw.fanfwmessenger.net.ParamsList.Parameter;
import com.fanfanw.fanfwmessenger.net.ParamsList.StringParameter;

public class HttpRequestUtil {

	public static ParamsList newParams() {
		return new ParamsList();
	}

	public static HttpRequest getMethod(String url, ParamsList paramsList)
			throws HttpRequestException {
		final String baseUrl = url.toString();
		ArrayList<HeaderParameter> headerList = new ArrayList<HeaderParameter>();

		final StringBuilder result = new StringBuilder(baseUrl);
		if (paramsList != null && paramsList.size() > 0) {

			if (baseUrl.indexOf(':') + 2 == baseUrl.lastIndexOf('/'))
				result.append('/');

			// Add '?' if missing and add '&' if params already exist in base
			// url
			final int queryStart = baseUrl.indexOf('?');
			final int lastChar = result.length() - 1;
			if (queryStart == -1)
				result.append('?');
			else if (queryStart < lastChar && baseUrl.charAt(lastChar) != '&')
				result.append('&');
			for (int i = 0; i < paramsList.size(); i++) {
				Parameter param = paramsList.get(i);
				if (param instanceof StringParameter) {
					StringParameter strParam = (StringParameter) param;
					if (i != 0) {
						result.append('&');
					}
					result.append(strParam.name);
					result.append('=');
					result.append(strParam.value);
				}

				if (param instanceof HeaderParameter) {
					headerList.add((HeaderParameter) param);
				}

			}
		}

		HttpRequest request = HttpRequest.get(result.toString());

		for (HeaderParameter param : headerList) {
			request.header(param.name, param.value);
		}

		return request;
	}

	public static HttpRequest postMethod(String url, ParamsList paramsList) {
		HttpRequest request = HttpRequest.post(url);

		ArrayList<HeaderParameter> headerList = new ArrayList<HeaderParameter>();

		if (paramsList != null && paramsList.size() > 0) {
			for (int i = 0; i < paramsList.size(); i++) {
				Parameter param = paramsList.get(i);
				if (param instanceof HeaderParameter) {
					headerList.add((HeaderParameter) param);
				}

			}
		}

		for (HeaderParameter param : headerList) {
			request.header(param.name, param.value);
		}

		if (paramsList != null && paramsList.size() > 0) {
			for (int i = 0; i < paramsList.size(); i++) {
				Parameter param = paramsList.get(i);
				if (param instanceof StringParameter) {
					StringParameter strParam = (StringParameter) param;
					request.part(strParam.name, strParam.value);
				}

				if (param instanceof InputStreamParameter) {
					InputStreamParameter ipsParam = (InputStreamParameter) param;
					request.part(ipsParam.name, ipsParam.fileName, null,
							ipsParam.value);
				}

				if (param instanceof FileParameter) {
					FileParameter fileParam = (FileParameter) param;
					request.part(fileParam.name, fileParam.value.getName(),
							fileParam.value);
				}
			}
		}

		return request;
	}

	public static String getRequestResult(HttpRequest request) {
		return getRequestResult(request, "UTF-8");
	}

	public static String getRequestResult(HttpRequest request, String charset) {
		if (request.ok()) {
			return request.body(charset);
		}
		return null;
	}

}
*/